/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-05-20
 * Time: 16:06
 */
//力扣 209 滑动窗口
class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        //同向双指针，滑动窗口
        int n = nums.length;
        int len = Integer.MAX_VALUE;
        int sum = 0;
        for (int left = 0, right = 0; right < n; right++) {
            sum += nums[right];//进窗口
            while (sum >= target) {//判断
                len = Math.min(len, right - left + 1);//更新结果
                sum -= nums[left++];//出窗口---判断
            }
        }
        return len == Integer.MAX_VALUE ? 0 : len;
    }
}